<?php
class superAdminAction extends sfActions
{
	public function execute()
	{
		if ($this->getRequest()->getMethod() != sfRequest::POST)
		{
			$this->sqlString = null;
			$this->permission = true;
			$c = new Criteria();
			$this->sqlLists = SqlStatisticAdminPeer::doSelect($c);
			$this->result = null;
		}
		else
		{
			$this->optValue = $this->getRequestParameter('optStatisticType');
			$this->actionType = $this->getRequestParameter('action_type');
			$sqlString  = $this->getRequestParameter('sqlString');

			$c = new Criteria();
			if ($this->actionType == 'update')
			{
				$asName  = $this->getRequestParameter('asName');
				//$id  = $this->getRequestParameter('id');

				$this->currentSql = new SqlStatisticAdmin();

				if ($asName != null)
				{
					$c->add(SqlStatisticAdminPeer::NAME, $asName);
					$this->currentSql = SqlStatisticAdminPeer::doSelectOne($c);

					if (!$this->currentSql)
					{
						$this->currentSql = new SqlStatisticAdmin();
						$this->currentSql->setNew(true);;
						$this->currentSql->setName($asName);

						if ($sqlString!=null) {
							$this->currentSql->setSqlString($sqlString);
						}
						$this->currentSql->save();
						$this->optValue = $this->currentSql->getId();
					}
				}
				elseif ($this->optValue != null)
				{
					$this->currentSql->setId($this->optValue);
					//$this->currentSql = SqlStatisticAdminPeer::doSelectOne($sql->buildCriteria());
					$this->currentSql->setSqlString($sqlString);
					$this->currentSql->setNew(false);
					$this->currentSql->save();
				}
			}
			else if ($this->actionType == "get")
			{
				$c->add(SqlStatisticAdminPeer::ID, $this->optValue);
				$this->currentSql = SqlStatisticAdminPeer::doSelectOne($c);
				$sqlString = $this->currentSql->getSqlString();
			}

			if ($sqlString != null)
			{
				$sqlString = trim($sqlString);
				$subSql = substr($sqlString, 0, 6);
				if ( strtolower($subSql) == "select")
				{
					$this->result = SqlStatisticAdminPeer::getStatistic($sqlString);
					$this->permission = true;
				}
				else
				{
					$this->permission = false;
				}
			}
			$c = new Criteria();
			$this->sqlLists = SqlStatisticAdminPeer::doSelect($c);
		}
	}
}
?>